INCLUDE(CheckIncludeFile)
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckIncludeFileCXX)
INCLUDE(CheckLibraryExists)


#SET( CMAKE_CXX_FLAGS "-pipe -Wall -g -DHAVE_MPI=1")
#SET( CMAKE_C_FLAGS "-pipe -Wall -g -DHAVE_MPI=1")
SET( CMAKE_CXX_FLAGS "-O3 -DNDEBUG -std=c++0x -DHAVE_MPI=1")
SET( CMAKE_C_FLAGS "-O3 -DNDEBUG -DHAVE_MPI=1")

OPTION(ENABLE_INSTANTIATION_MODE "Instantiation mode" ON )
MARK_AS_ADVANCED(ENABLE_INSTANTIATION_MODE)
IF ( ENABLE_INSTANTIATION_MODE )
ADD_DEFINITIONS( -DLIFE_INSTANTIATION_MODE=1 )
ENDIF()

#
# Blas and Lapack
#
FIND_LIBRARY(BLAS_LIBRARY  blas )
CHECK_LIBRARY_EXISTS("blas" "sdot_" "${BLAS_LIBRARY_DIR}" BLAS_LIBRARY_EXISTS)

FIND_LIBRARY(LAPACK_LIBRARY NAMES lapack )
CHECK_LIBRARY_EXISTS("lapack" "dpotrf_" "${LAPACK_LIBRARY_DIR}" LAPACK_LIBRARY_EXISTS)
SET(LAPACK_LIBRARIES ${LAPACK_LIBRARY} ${BLAS_LIBRARY})
LINK_DIRECTORIES(${LAPACK_LIBRARIES})

#
# Mpi
#
INCLUDE(FindMPI.cmake)
INCLUDE_DIRECTORIES(${MPI_INCLUDE_PATH})
LINK_DIRECTORIES(${MPI_LIBRARY_PATH})
#ADD_DEFINITIONS( -DMPICH_IGNORE_CXX_SEEK )
SET(CMAKE_REQUIRED_INCLUDES "${MPI_INCLUDE_PATH};${CMAKE_REQUIRED_INCLUDES}")
IF ( MPI_INCLUDE_PATH AND MPI_LIBRARY_PATH )
  ADD_DEFINITIONS( -DHAVE_MPI -DHAVE_MPI_H )
ENDIF()

#
# Vtk
#
#FIND_PACKAGE(VTK QUIET)
#INCLUDE_DIRECTORIES(${VTK_INCLUDE_DIRS})
#LINK_DIRECTORIES(${VTK_LIBRARY_DIRS})
#
# VTK
#
FIND_PACKAGE(VTK)
if ( VTK_FOUND )
  set(HAVE_VTK 1)
  SET(VTK_LIBRARIES "-lvtkRendering -lvtkGraphics -lvtkImaging -lvtkCommon" )
  INCLUDE_DIRECTORIES(${VTK_INCLUDE_DIRS})
  MARK_AS_ADVANCED( VTK_DIR )
endif()

#
# XML
#
INCLUDE(FindXml2.cmake)
INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
LINK_DIRECTORIES(${LIBXML2_LIBRARIES})

#
# Boost
#
#date_time filesystem system program_options unit_test_framework signals  ${LIFE_BOOST_MPI} regex  serialization)


FIND_PACKAGE(Boost COMPONENTS date_time filesystem system program_options unit_test_framework signals mpi regex  serialization)
set(Boost_ADDITIONAL_VERSIONS "1.39" "1.40" "1.41" "1.42" )
set( BOOST_PARAMETER_MAX_ARITY 15 )
add_definitions( -DBOOST_PARAMETER_MAX_ARITY=${BOOST_PARAMETER_MAX_ARITY} -DBOOST_TEST_DYN_LINK )

#FIND_PACKAGE(Boost)
#SET(BOOST_LIBRARIES boost_program_options boost_filesystem boost_signals boost_mpi boost_serialization)
#set( BOOST_PARAMETER_MAX_ARITY 15 )
#add_definitions( -DBOOST_PARAMETER_MAX_ARITY=${BOOST_PARAMETER_MAX_ARITY} -DBOOST_TEST_DYN_LINK )
#
# Metis
#
INCLUDE(FindMetis.cmake)
INCLUDE_DIRECTORIES(${METIS_INCLUDE_DIR})
LINK_DIRECTORIES(${METIS_LIBRARIES})

#
# Petsc
#
INCLUDE(FindPetsc.cmake)
INCLUDE_DIRECTORIES(${PETSC_INCLUDE_DIR} ${PETSCCONF_INCLUDE_DIR})
LINK_DIRECTORIES(${PETSC_LIBRARIES})

#
# slpec
#
find_path (SLEPC_DIR include/slepc.h
  HINTS ENV SLEPC_DIR
  PATHS
  /usr/lib/slepcdir/3.0.0 # Debian
  $ENV{HOME}/slepc
  DOC "SLEPc Directory")
SET(CMAKE_REQUIRED_INCLUDES "${SLEPC_DIR}/include;${CMAKE_REQUIRED_INCLUDES}")
CHECK_INCLUDE_FILE( slepc.h HAVE_SLEPC_H )
FIND_LIBRARY(SLEPC_LIB_SLEPC     slepc )
SET(SLEPC_LIBRARIES ${SLEPC_LIB_SLEPC})
message( "*** SLEPc directory : ${SLEPC_DIR}" )
if (HAVE_SLEPC_H AND SLEPC_DIR)
  set(HAVE_SLEPC 1)
endif()

#
# parpack
#
FIND_LIBRARY(PARPACK_LIBRARY NAMES parpack)
if (PARPACK_LIBRARY)
    SET(PARPACK_LIBRARIES ${PARPACK_LIBRARY})
endif()

#
# Trilinos
#
INCLUDE(FindTrilinos.cmake)
INCLUDE_DIRECTORIES(${TRILINOS_INCLUDE_DIR})

#
# Life
#
INCLUDE(FindLife.cmake)
INCLUDE_DIRECTORIES(${LIFE_INCLUDE_DIR})
LINK_DIRECTORIES(${LIFE_LIBRARIES})

#
# GMM
#
INCLUDE_DIRECTORIES(	${LIFE_DIR}/include/life)



SET(THELIBS
  ${LIBXML2_LIBRARIES}
  ${LIFE_LIBRARIES}
  ${TRILINOS_LIBRARIES}
  ${BOOST_LIBRARIES}
  ${METIS_LIBRARIES}
  ${MPI_LIBRARIES}
  ${LAPACK_LIBRARIES}
  ${PETSC_LIBRARIES}
  ${SLEPC_LIBRARIES}
  ${PARPACK_LIBRARIES}
  ${VTK_LIBRARIES}
  )


SET(THEINCLUDE
  ${MPI_INCLUDE_PATH}
  ${VTK_INCLUDE_DIRS}
  ${Boost_INCLUDE_DIRS}
  ${LIBXML2_INCLUDE_DIR}
  ${METIS_INCLUDE_DIR}
  ${PETSC_INCLUDE_DIR} 
  ${PETSCCONF_INCLUDE_DIR}
  ${TRILINOS_INCLUDE_DIR}
  ${LIFE_INCLUDE_DIR}
  ${LIFE_DIR}/contrib/gmm/include/
  )








